package cn.cms.util;

import cn.cms.dao.PageDao;

/**
 * Created by leon on 2017/2/21.
 */
public class PageUtil<T> {

    private PageDao<T> pageDao;

    public PageDao<T> getPageDao() {
        return pageDao;
    }

    public void setPageDao(PageDao<T> pageDao) {
        this.pageDao = pageDao;
    }

    public PageUtil(PageDao<T> pageDao, long totalCount) {

        this.setPageDao(pageDao);
        this.pageDao.setTotalCount(totalCount);
    }

    public int getLimitStart() {

        if (this.pageDao.getTotalCount() > 0){

            pageDao.limitStart = this.pageDao.getPageNo() * pageDao.pageSize;
            if (pageDao.limitStart >= this.pageDao.getTotalCount()){

                pageDao.limitStart = (int) this.pageDao.getTotalCount();
            }
        }else{

            pageDao.limitStart = 0;
        }

        return pageDao.limitStart;
    }

    public int getPageSize() {
        return pageDao.pageSize;
    }
}
